home *** CD-ROM | disk | FTP | other *** search
/ PC Users 8 / Cd Pc Users extra 8.iso / prog / inst / firstimp / vcimpres.z / sun.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-11-07  |  9.6 KB  |  297 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "LightSource Vector Example"
  5.    ClientHeight    =   7410
  6.    ClientLeft      =   1245
  7.    ClientTop       =   2310
  8.    ClientWidth     =   9495
  9.    Height          =   7815
  10.    Left            =   1185
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   7410
  15.    ScaleWidth      =   9495
  16.    Top             =   1965
  17.    Width           =   9615
  18.    Begin VB.CommandButton cmdAnimate 
  19.       Caption         =   "Animate"
  20.       Height          =   435
  21.       Left            =   7800
  22.       TabIndex        =   13
  23.       Top             =   4920
  24.       Width           =   1155
  25.    End
  26.    Begin VB.Frame Frame2 
  27.       Caption         =   " Set Vector By Time "
  28.       Height          =   1935
  29.       Left            =   7440
  30.       TabIndex        =   9
  31.       Top             =   2640
  32.       Width           =   1815
  33.       Begin VB.TextBox txtTime 
  34.          Height          =   285
  35.          Left            =   360
  36.          TabIndex        =   11
  37.          Text            =   "Time"
  38.          Top             =   960
  39.          Width           =   1155
  40.       End
  41.       Begin VB.CommandButton cmdSetTime 
  42.          Caption         =   "Set Time"
  43.          Height          =   315
  44.          Left            =   360
  45.          TabIndex        =   10
  46.          Top             =   1440
  47.          Width           =   1155
  48.       End
  49.       Begin VB.Label Label1 
  50.          Caption         =   "0 = Midnight  0.5 = Noon"
  51.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  52.             Name            =   "Arial"
  53.             Size            =   9
  54.             Charset         =   0
  55.             Weight          =   400
  56.             Underline       =   0   'False
  57.             Italic          =   0   'False
  58.             Strikethrough   =   0   'False
  59.          EndProperty
  60.          Height          =   495
  61.          Left            =   420
  62.          TabIndex        =   12
  63.          Top             =   360
  64.          Width           =   1155
  65.       End
  66.    End
  67.    Begin VB.Frame Frame1 
  68.       Caption         =   " Light Vector "
  69.       Height          =   2115
  70.       Left            =   7440
  71.       TabIndex        =   1
  72.       Top             =   240
  73.       Width           =   1815
  74.       Begin VB.TextBox txtY 
  75.          Height          =   285
  76.          Left            =   420
  77.          TabIndex        =   5
  78.          Text            =   "Y"
  79.          Top             =   780
  80.          Width           =   1215
  81.       End
  82.       Begin VB.TextBox txtZ 
  83.          Height          =   285
  84.          Left            =   420
  85.          TabIndex        =   4
  86.          Text            =   "Z"
  87.          Top             =   1140
  88.          Width           =   1215
  89.       End
  90.       Begin VB.TextBox txtX 
  91.          Height          =   285
  92.          Left            =   420
  93.          TabIndex        =   3
  94.          Text            =   "X"
  95.          Top             =   420
  96.          Width           =   1215
  97.       End
  98.       Begin VB.CommandButton cmdSetVector 
  99.          Caption         =   "Set Vector"
  100.          Height          =   315
  101.          Left            =   360
  102.          TabIndex        =   2
  103.          Top             =   1620
  104.          Width           =   1155
  105.       End
  106.       Begin VB.Label Label2 
  107.          Caption         =   "X:"
  108.          Height          =   255
  109.          Index           =   0
  110.          Left            =   180
  111.          TabIndex        =   8
  112.          Top             =   480
  113.          Width           =   195
  114.       End
  115.       Begin VB.Label Label2 
  116.          Caption         =   "Y:"
  117.          Height          =   255
  118.          Index           =   1
  119.          Left            =   180
  120.          TabIndex        =   7
  121.          Top             =   840
  122.          Width           =   195
  123.       End
  124.       Begin VB.Label Label2 
  125.          Caption         =   "Z:"
  126.          Height          =   255
  127.          Index           =   2
  128.          Left            =   180
  129.          TabIndex        =   6
  130.          Top             =   1200
  131.          Width           =   195
  132.       End
  133.    End
  134.    Begin VtChartLib.VtChart VtChart1 
  135.       Height          =   6615
  136.       Left            =   60
  137.       TabIndex        =   0
  138.       Top             =   60
  139.       Width           =   7215
  140.       _ExtentX        =   12726
  141.       _ExtentY        =   11668
  142.       _0              =   $"sun.frx":0000
  143.       _1              =   $"sun.frx":0405
  144.       _2              =   $"sun.frx":080A
  145.       _3              =   $"sun.frx":0C0F
  146.       _4              =   $"sun.frx":1016
  147.       _5              =   $"sun.frx":141C
  148.       _6              =   $"sun.frx":1822
  149.       _7              =   $"sun.frx":1C28
  150.       _8              =   $"sun.frx":202D
  151.       _9              =   $"sun.frx":2432
  152.       _10             =   $"sun.frx":2837
  153.       _11             =   $"sun.frx":2C3C
  154.       _12             =   $"sun.frx":3041
  155.       _13             =   $"sun.frx":3446
  156.       _14             =   $"sun.frx":384B
  157.       _15             =   $"sun.frx":3C50
  158.       _count          =   16
  159.       _ver            =   1
  160.    End
  161. Attribute VB_Name = "Form1"
  162. Attribute VB_Creatable = False
  163. Attribute VB_Exposed = False
  164.  Sub LoadSufaceData(filename$)
  165.    Dim rows%, cols%, i%, j%, junk$, value#
  166.    On Error GoTo LoadSufaceDataError
  167.    Open filename For Input As #1
  168.    Input #1, junk, rows
  169.    Input #1, junk, cols
  170.    With VtChart1
  171.       .RowCount = rows
  172.       .ColumnCount = cols
  173.       With .DataGrid
  174.          For i = 1 To rows
  175.             For j = 1 To cols
  176.                Input #1, value
  177.                .SetData i, j, value, False
  178.             Next j
  179.          Next i
  180.       End With
  181.    End With
  182.    Close #1
  183.       
  184.    Exit Sub
  185. LoadSufaceDataError:
  186.    MsgBox Error
  187. End Sub
  188.  Sub FormatSurfaceChart()
  189.    Dim i As Integer
  190.    Dim attr As Object
  191.    With VtChart1
  192.       .chartType = VtChChartType3dSurface
  193.       .Backdrop.Fill.Style = VtFillStyleBrush
  194.       .Backdrop.Fill.Brush.FillColor.Set 64, 192, 192
  195.       
  196.       With .Plot
  197.          .Light.EdgeVisible = False
  198.          .Elevation.Surface.WireframePen.Style = VtPenStyleNull
  199.          .Elevation.Surface.DisplayType = VtChSurfaceDisplayTypeCBands
  200.          .PlotBase.BaseHeight = 0
  201.          .Wall.Pen.Style = VtPenStyleNull
  202.          
  203.          .Axis(VtChAxisIdZ).AxisGrid.MajorPen.Style = VtPenStyleNull
  204.          .Axis(VtChAxisIdZ).AxisScale.Hide = True
  205.          
  206.          .Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleNull
  207.          .Axis(VtChAxisIdY).AxisScale.Hide = True
  208.          
  209.          .Axis(VtChAxisIdY2).AxisGrid.MajorPen.Style = VtPenStyleNull
  210.          .Axis(VtChAxisIdY2).AxisScale.Hide = True
  211.          
  212.          .Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleNull
  213.          .Axis(VtChAxisIdX).AxisScale.Hide = True
  214.          
  215.          .View3d.Set 58, 16
  216.          
  217.          With .Elevation
  218.             '' Set up the contours
  219.             .AutoValues = False
  220.             .ColorType = VtChContourColorTypeManual
  221.             
  222.             With .Attributes
  223.                For i = 1 To .Count - 5
  224.                   .Remove (i)
  225.                Next i
  226.                
  227.                '' Set contour values and their color
  228.                .Item(1).value = 0
  229.                .Item(2).value = 0.01
  230.                .Item(3).value = 43
  231.                .Item(4).value = 43.5
  232.                .Item(5).value = 50
  233.                
  234.                .Item(1).Brush.FillColor.Set 0, 0, 202
  235.                .Item(2).Brush.FillColor.Set 0, 0, 202
  236.                .Item(3).Brush.FillColor.Set 10, 128, 10
  237.                .Item(4).Brush.FillColor.Set 210, 210, 210
  238.                .Item(5).Brush.FillColor.Set 255, 255, 255
  239.             End With
  240.             
  241.             For Each attr In .Attributes
  242.                attr.Brush.Style = VtBrushStyleSolid
  243.             Next attr
  244.             
  245.          End With
  246.       End With
  247.    End With
  248. End Sub
  249. Sub SetLightForTime(ch As Object, theTime!)
  250. '' Times are in the spreadsheet serial number format where
  251. '' 1 = a day so zero = midnight and 0.5 = noon. For trig
  252. '' functions Pi/2 = midnight and 3Pi/2 = noon. The code
  253. '' below maps time to light source coordinates. We also throw
  254. '' in some ambient intensity to simulate the reflected light
  255. '' during midday. Note that we are setting the direction
  256. '' of the sun's rays, not its position. See the associated
  257. '' readme for chart/light coordinate systems.
  258.    Const r = 20
  259.    Const HALFPI = 1.5708
  260.    Dim radians!, x!, y!, z!
  261.    radians = (theTime / 0.25) * HALFPI + HALFPI
  262.    x = r * Cos(radians)
  263.    y = r * Sin(radians)
  264.    z = -0.1 + theTime
  265.    ch.Plot.Light.LightSources.Item(1).Set x, y, z, 1
  266.    ch.Plot.Light.AmbientIntensity = 1.25 * (IIf(theTime > 0.5, 1 - theTime, theTime))
  267.    txtX.Text = Str(x)
  268.    txtY.Text = Str(y)
  269.    txtZ.Text = Str(z)
  270. End Sub
  271. Private Sub cmdAnimate_Click()
  272.    Static when!
  273.    For when = 0 To 1 Step 0.05
  274.       SetLightForTime VtChart1, when
  275.       txtTime.Text = Format(when, "hh:mm")
  276.       DoEvents
  277.    Next when
  278. End Sub
  279. Private Sub cmdSetTime_Click()
  280.    Dim theTime!
  281.    theTime = Val(txtTime.Text)
  282.    If theTime >= 0 And theTime <= 1 Then
  283.       txtTime.Text = Format(theTime, "hh:mm")
  284.       SetLightForTime VtChart1, theTime
  285.    Else
  286.       MsgBox "Time must be a number between 0 and 1."
  287.    End If
  288.       
  289. End Sub
  290. Private Sub cmdSetVector_Click()
  291.    VtChart1.Plot.Light.LightSources.Item(1).Set Val(txtX.Text), Val(txtY.Text), Val(txtZ.Text), 1
  292. End Sub
  293. Private Sub Form_Load()
  294.    LoadSufaceData App.Path & "\surfdata.txt"
  295.    FormatSurfaceChart
  296. End Sub
  297.